function [ EC ] = APEbatchramanshift( exwavelength, PathName )
% [ EC ] = APEbatchramanshift( exwavelength, PathName )
%
%   Converts the raw datax in datasetname from assumed wavelength in nm to
%   Raman shift in cm^-^1 using the Laser Excitation Wavelength
%   exwavelength in nm.
%   The result will be saved in the same file as ramandatax.
%
% INPUT     exwavelength    :   Laser excitation wavelength in nm
%           (PathName)      :   Path to files. Optional.
%
% OUTPUT            EC      :   Error Code. (0=success, 1=error)

% DEPENDENCIES              - ramanshift.m

%  (c) F. Dworkowski, 2012-14
%      Version 1.2, 2014-01-27


%% ===== Config =====
EC = 0;
oldpath=cd;


%% ===== CODE =====
% ----- check for input argument -----
 
if nargin<1,
    help APEbatchramanshift
    EC = 1;
    return
end

% ----- Choose Folder and detect files -----
if nargin <2 || (~ischar(PathName) && PathName>0)
    [FileName,PathName,FilterIndex] = uigetfile({'*.mat';'*.*'});
    if isequal(PathName,0)
       disp('User selected Cancel')
       EC = 1;
       return
    else
       disp(['User selected ', fullfile(PathName, FileName)])
    end
else
    FilterIndex = 1;
end

if ischar(PathName) && ~isempty(PathName)
    cd(PathName)
end

if FilterIndex == 2
    filelist=dir('*.*');        % Detect all available files
else
    filelist=dir('*.mat');      % Detect all available .mat files
end

for i = 1:length(filelist)      % Do for all detected files
    [pathstr, datasetname, ext] = fileparts(filelist(i).name);
    dset=load(datasetname);
    
    dset.Laser_exwavelength = exwavelength;
    dset.ramandatax = ramanshift(dset.datax, exwavelength);
    
    save(datasetname,'-struct','dset')
end
    EC = 0;

end

